import time

from selenium.webdriver.common.by import By

from common.Utils import ForumDriver


#论坛注册页面
class ForumEnroll:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:58080/sign-in.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)
    #注册页面正常进入
    def ForumEnrollSuclogin(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
        #查看是否进入注册页面
        ForumDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR,"#submit")

    #正确注册
    def ForumEnrollSuc(self):
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("赵六")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("二流子")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.implicitly_wait(3)
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a")
        time.sleep(2)
    #注册失败-已存在该用户名
    def ForumEnrollFail1(self):
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("张三")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("二流子")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.implicitly_wait(3)
        ForumDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")
    # 注册失败-没有输入用户名
    def ForumEnrollFail2(self):
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("二流子")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.implicitly_wait(3)
        ForumDriver.getScreeShot()
        actual=self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(2) > div").text
        print(actual)
        assert actual == "用户名不能为空"

    # 注册失败-没有输入昵称
    def ForumEnrollFail3(self):
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("张三")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.implicitly_wait(3)
        ForumDriver.getScreeShot()
        actual = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(3) > div").text
        print(actual)
        assert actual == "昵称不能为空"

    # 注册失败-没有输入密码
    def ForumEnrollFail4(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("张三")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("二流子")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.implicitly_wait(3)
        ForumDriver.getScreeShot()
        actual = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(4) > div > div").text
        print(actual)
        assert actual == "密码不能为空"

    # 注册失败-密码二次错误
    def ForumEnrollFail5(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("张三")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("二流子")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456789")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.implicitly_wait(3)
        ForumDriver.getScreeShot()
        actual = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(5) > div > div").text
        print(actual)
        assert actual == "请检查确认密码"
    # 注册失败-密码二次错误
    def ForumEnrollFail6(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("张三")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("二流子")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.implicitly_wait(3)
        ForumDriver.getScreeShot()


enroll=ForumEnroll()
enroll.ForumEnrollSuclogin()
# enroll.ForumEnrollSuc()
# enroll.ForumEnrollFail1()
# enroll.ForumEnrollFail2()
# enroll.ForumEnrollFail3()
# enroll.ForumEnrollFail4()
# enroll.ForumEnrollFail5()
enroll.ForumEnrollFail6()